package cn.tedu.front.details.service.Impl;

import cn.tedu.common.enumerator.ServiceCode;
import cn.tedu.common.ex.ServiceException;
import cn.tedu.front.details.dao.cache.IJobCacheRepository;
import cn.tedu.front.details.dao.persist.repository.IJobRepository;
import cn.tedu.front.details.pojo.vo.JobVO;
import cn.tedu.front.details.service.IJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class JobServiceImpl implements IJobService {
    @Autowired
    private IJobRepository iJobRepository;
    @Autowired
    private IJobCacheRepository jobCacheRepository;
    @Override
    public void rebuildCache() {
        List<JobVO> standard = iJobRepository.getStandard();
        for (JobVO jobVO : standard) {
            Long id = jobVO.getId();
            jobCacheRepository.saveJob(id,jobVO);
        }
    }

    @Override
    public JobVO getStandardById(Long id) {
        //根据id查询职位描述
        JobVO queryResult = iJobRepository.getStandardById(id);
        if(queryResult == null){
            String message = "查询文章详情失败，文章数据不存在！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND, message);
        }
        return queryResult;
    }

    @Override
    public List<JobVO> getStandard() {
        //查询所有的VO集合
        return iJobRepository.getStandard();
    }
}
